//
//  Tooth.swift
//  DentalFormula
//
//  Created by AMalashin on 23.09.2023.
//

import Foundation

enum ToothType {
    case Canine
    case Incisor
    case Premolar
    case Molar
}

enum ToothCondition: String {
    case intact = "tooth.condition.intact"
    case decay = "tooth.condition.decay"
    case filling = "tooth.condition.filling"
    case decayFilling = "tooth.condition.decay-filling"
    case missed = "tooth.condition.missed"
    case unknown = "unknown"
    
    func localized() -> String {
//        let localizedKey = String.LocalizationValue(stringLiteral: self.rawValue)
//        return String(localized: localizedKey)
        return NSLocalizedString(self.rawValue, comment: "")
    }
}

struct Tooth: CustomStringConvertible, Equatable {
    var number: Int
    var type: ToothType
    var condition: ToothCondition?
    
    init?(number: Int, condition: ToothCondition? = nil) {
        self.number = number
        self.condition = condition

        switch number {
        case 13, 23, 33, 43:
            self.type = .Canine
        case 11, 12, 21, 22, 31, 32, 41, 42:
            self.type = .Incisor
        case 14, 15, 24, 25, 34, 35, 44, 45:
            self.type = .Premolar
        case 16, 17, 18, 26, 27, 28, 36, 37, 38, 46, 47, 48:
            self.type = .Molar
        default: return nil
        }
    }
    
    var description: String {
        return "\(number) \(condition ?? .unknown)"
    }
    
    static func == (lhs: Tooth, rhs: Tooth) -> Bool {
        return lhs.number == rhs.number && lhs.condition == rhs.condition
    }
}
